#ifndef LOGMANAGER_H
#define LOGMANAGER_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool. 

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.
  
*/

#include <iostream>
#include <fstream>

using namespace std;

/*
  The Log Manager is responsible for saving messages to an ASCII file.
  It is implemented as a singleton and is easily accessible from anywhere in the application.
  By default, the log file is created in the executable directory (win and linux) or in the app
  bundle directory (mac), and is overwritten every game session. The log file path can optionally be
  changed by passing a different argument to setLogFile().

  Messages are always logged with a leading time stamp, in the format: DAY/MONTH/YEAR HOUR/MIN/SEC.FRACTION

  If debug mode is off, only messages regarding the application status at startup and shutdown
  are logged. If debug mode is on, other optional messages may be logged.

  Note: the MainWindow will load the following options from from the config.xml file, so that they can be
  changed at runtime without the need to recompile:
        - log file name (with an optional  relative path)
        - debug mode on/off
  These options must be manually edited in the XML file as they are not exposed in the GUI.
*/
class CLogManager
{
public:

    CLogManager(const char* argv0);
    ~CLogManager();

    static CLogManager* getSingleton();

    void setDebugMode(bool active);
    bool isDebugModeActive();
    void setLogFile(const char* logFileName = "log.txt");
    void logMessage(const char* message);
    void logMessage(const string& message);

private:

    static CLogManager* uniqueInstance;

    string mLogWriteDir;
    ofstream mLogFile;
    bool mDebugModeActive;
};

#endif // LOGMANAGER_H
